<template>
	<view class="currentPage">
		<topCard :userInfo='userInfo' :isTrila="isTrila"></topCard>
		<botCard :botObj='botObj' ref="botCard" @getTips="getTips" style="position: relative;
    top: -50px;" :isTrila="isTrila"></botCard>
		<!-- <functionList @changeInfo="confirm"></functionList> -->
		<!-- 退出登录 -->
		<u-button class="custom-style" text="退出登录" @click='tapBtn' v-if="userInfo"
			customStyle="background: linear-gradient(90deg, #2CB9A4 0%, #C7EACE 100%);color:#fff;border-radius: 30px;width:90%;margin-bottom: 50px;">
		</u-button>
		<!-- 占位符 -->
		<view style="height: 100upx;width: 100%;" v-if="userInfo">
		</view>
		<u-modal :show="show" :closeOnClickOverlay="true" :showCancelButton='true' :title="'提示'" @confirm='confirm'
			@cancel='cancel' :content="'是否退出登录？'" confirmColor="#2CB9A4"></u-modal>
		<u-notify ref="uNotify" message="Hi uView"></u-notify>
		<m-tabbar native>
		</m-tabbar>
	</view>
</template>

<script>
	import qrInfo from '@/components/my/qrInfo.vue'
	import functionList from '@/components/my/functionList.vue'
	import topCard from '@/components/my/topCard.vue'
	import botCard from '@/components/my/botCard.vue'
	import buttonOperation from '@/components/common/buttonOperation.vue'
	import eventBUs from '../../utils/eventBus.js'
	import {
		getMerchant,
		logout
	} from '@/request/api.js'
	export default {
		components: {
			qrInfo,
			topCard,
			botCard,
			buttonOperation,
			functionList
		},
		data() {
			return {
				isLogin: false,
				// userInfo: {
				// 	avatar: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
				// 	nickname: '波比',
				// 	mobile: "18487301491"
				// },
				userInfo: null,
				show: false,
				botObj: {},
				isTrila:0,//默认是非飞狗平台
			}
		},
		onShareAppMessage() {
			return {
				title: '',
				path: '/pages/my/my',

			}
		},
		onShareTimeline: function() {
			return {
				title: '',
				path: '/pages/my/my',
			}
		},
		onLoad(res) {
			// console.log(res,1111)
			let token = uni.getStorageSync('shopToken')
			// console.log(token,'token')
			// return
			if (token) {
				this.getMerchant()
			}
		},
		onShow() {
			setTimeout(() => {
				this.$refs.botCard.getMerchantConfig()
				this.$refs.botCard.getConfig()
				this.$refs.botCard.census()
				this.$refs.botCard.getMoney()
			}, 1000)

			let token = uni.getStorageSync('shopToken')
			// console.log(token,'token')
			// return
			if (token) {
				this.getMerchant()
				// this.$refs.botCard.getConfig()
			}
			this.$eventBus.$on('hasLogin', val => {
				if (val) this.isLogin = true
				let userInfo = uni.getStorageSync('userInfo')
				console.log(userInfo)
				this.userInfo = userInfo
			});
		},
		methods: {
			getTips(e) {
				this.$refs.uNotify.show({
					top: 0,
					type: 'success',
					color: '#2CB9A4',
					bgColor: '#fff',
					message: e,
					duration: 1000 * 4,
					fontSize: 14,
					safeAreaInsetTop: false
				})

			},
			async getMerchant() {
				let res = await getMerchant();
				this.isTrila = res.data.is_trila 
				console.log(this.isTrila,'isTrila')
				uni.setStorageSync('userInfo', res.data)
				this.userInfo = {
					avatar: res.data.merchant.logo,
					nickname: res.data.name,
					mobile: res.data.mobile
				}
				this.botObj = res.data
			},
			tapBtn() {
				this.show = true
			},
			async confirm() {
				// console.log(222)
				let res = await logout()
				uni.removeStorageSync('shopToken')
				uni.removeStorageSync('userInfo')
				this.show = false
				this.userInfo = null
				this.$refs.botCard.clearData()
				uni.showToast({
					icon: 'none',
					title: '退出成功！'
				})
			},
			cancel() {
				this.show = false
			}
		}
	}
</script>
<style>
	page {
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	::v-deep .date-time-picker .date-time-container .time-picker-tool .confirm-btn {
		color: #2CB9A4 !important;
	}

	.currentPage {
		min-height: 100vh;
		background-color: #fff;
		overflow: hidden;
		padding-bottom: 20px;
	}

	.custom_style {
		color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 24rpx;

		&_icon {
			// background-color: #15357A;
			background-image: url(../../static/tabble/tab2.png);
			font-size: 65rpx;
			width: 90rpx;
			height: 90rpx;
			border-radius: 100%;
			display: flex;
			background-repeat: no-repeat;
			background-size: 100%;
			justify-content: center;
			align-items: center;
			margin-top: -40rpx;
		}
	}
</style>